#include("/front/teacher/_layout.html")
#@layout()
#define layoutImportcss()
#end
#define layoutHead()
	<title>助手</title>
	<style>
		.col-channel-a{ color: var(--f7-block-title-text-color); }
		.col-channel-box{ display:flex;align-items: center; margin: 10px 0 10px 0; }
		.col-channel-box img{ width:30px; height: 30px; }
		.col-channel-box label{ margin-left: 10px; }
	</style>
#end
#define layoutHome()

#include("inc_toolbar.html")

<div id="div_chanle_list" class="page-content hide-navbar-on-scroll assistant-page-content">
	<div class="banner">
		<img class="" src="/front/img/yszs.png">
	</div>
</div>
#end
#define layoutImportjs()
#end
#define layoutScript()
<script type="text/javascript">

	sendPost('/front/teacher/article/getArticleCat?type_id=1', null, function(res){
		if (res.code == 200){
			formatCatHtml(res.listcat);
		}else{
			alert(res.msg);
		}
	});
	
	function formatCatHtml(listcat){
		var shtml = '';
		var list1 = listcat.filter(function (e) { return e.parent_id == 0; });
		for(var i=0; i<list1.length; i++){
			var jdata1 = list1[i];
			
			shtml += '<div class="assistant-piece"><h3>'+jdata1.cat_name+'</h3>';
			shtml += '<div class="ass-box"><div class="ass-item">';
			
			var list2 = listcat.filter(function (e) { return e.parent_id == jdata1.cat_id; });
			for(var j=0; j<list2.length; j++){			
				shtml += getTemplateHtml(list2[j]);				
			}
			
			shtml += '</div></div></div>';
		}
		$$('#div_chanle_list').append(shtml);
	}
	
	function getCatIcon(cat_icon){
		if (isBlank(cat_icon)){
			return '<img src="/front/img/def_chanel.png" style="width:26px;height:26px;">';
		}else{
			return '<img src="'+cat_icon+'" style="width:26px;height:26px;">';
		}
	}
	function getListUrl(jdata){
		if (jdata.link_course === true || jdata.link_course === 1){
			return '/front/teacher/html/course_list?article_catid='+jdata.cat_id+'&catname='+encodeURI(encodeURI(jdata.cat_name));
		}else{
			return '/front/teacher/html/article_list?catid='+jdata.cat_id;
		}
	}
	
	function getTemplateHtml(jdata){
		//console.log(jdata);
		var shtml = `
						<a href="${getListUrl(jdata)}" class="external">
							<div class="col-channel-box">
								${getCatIcon(jdata.cat_icon)}<label>${formatNullValue(jdata.cat_name)}</label>
							</div>
						</a>
		`;
		
		return shtml;
	}
	
</script>
#end